﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.ClickCricket.bll;
using System.Web.UI.HtmlControls;


public partial class Controls_LetterSelector : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            GetPlayerList("A");
    }

    private void GetPlayerList(string playerLetter)
    {
        List<Player> _PlayerList = new List<Player>();
        _PlayerList = PlayerService.Instance.getPlayers(playerLetter);
        //Use aHTML table which has _playersLIst%3 columns and _playerListCOunt rows

        Int16 count = 0;
        Table tb = new Table();
        tb.BackColor = System.Drawing.Color.White;
        tb.BorderWidth = new Unit(1.5);
        tb.GridLines = GridLines.Both;
        tb.Width = 1000;

        
        for (int i = 0; i <= _PlayerList.Count / 3; i++)
        {
            TableRow tr = new TableRow();

            for (int j = 0; j < 3  && count < _PlayerList.Count ; j++)
            {
                Player player = (Player)_PlayerList[count];
                TableCell playerName = new TableCell();
                
                HyperLink playerLink = new HyperLink();
                playerLink.Text = player.PlayerFirstName + "," + player.PlayerLastName;
                
                playerLink.NavigateUrl = "~/PlayerDetails.aspx?PlayerId=" + player.PlayerId;
                playerName.Controls.Add(playerLink);
                tr.Cells.Add(playerName);
                count++;
            }
            tb.Rows.Add(tr);
            count++;
        }

        this.Controls.Add(tb);
        
    }
    protected void SetLetter(object sender, EventArgs e)
    {
        LinkButton letter = (LinkButton)sender;
        if (letter != null)
        {
            GetPlayerList(letter.Text);
        }
        
    }
}
